<div th:fragment="edit">

    <div class="modal fade" id="myModal"  tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel">编辑用户</h4>
                </div>
                <input type="hidden"  id ="id" name="id">
                <div class="modal-body">
                    <div class="form-group">
                        <label for="account" class="control-label">登录帐号:</label>
                        <input type="text" class="form-control" readonly="readonly" id="account" name="account">
                    </div>

                    <div class="form-group">
                        <label for="password" class="control-label">登录密码:</label>
                        <input type="password" class="form-control"   placeholder="请输入密码"  id="password" name="password">
                    </div>

                    <div class="form-group">
                        <label for="name" class="control-label">用户名称:</label>
                        <input type="text" class="form-control"  placeholder="请输入名称"  id="name" name="name">
                    </div>
                    <div class="form-group">
                        <label  class="control-label">用户名称:</label>
                        <select class="form-control" autocomplete="off" id="sex">
                            <option value="1" >男</option>
                            <option value="2" >女</option>
                        </select>
                    </div>

                </div>
                <div class="modal-footer">
                    <button id="edit" type="button" class="btn btn-success">确定</button>
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                </div>

            </div>
        </div>
    </div>

    <script>
       //加載用戶編輯彈框
       function EditViewById(id){
           $('#myModal').modal();
           const data = {
               id: id
           };
           myrequest("/admin/user/edit",data,'GET',function(data){
               $("#name").val(data.data.name);
               $("#account").val(data.data.account);
               $("#password").val('');
                $("#id").val(data.data.id);
               $("#sex").val(data.data.sex);
           }, function(data){
               toastr.error(data.msg);
           })
       }
        //点击保存按钮
        $("#edit").click(function(){

            const id = $("input[name='id']").val();//获取表单form1的用户名的值
            const account = $("input[name='account']").val();//获取表单form1的用户名的值
            const password = $("input[name='password']").val();//获取表单form1密码值
            const name = $("input[name='name']").val();//获取表单form1密码值
            const sex = $('#sex option:selected').val();

            const data = {
                account: account,
                password: password,
                name: name,
                id:id,
                sex:sex
            };
            //提交后台保存用户数据
            myrequest("/admin/user/edit",data,'POST',function(data){
                $('#myModal').modal('hide')
                toastr.success(data.msg);
                $("#table").bootstrapTable('refresh');
            }, function(data){
                $('#myModal').modal('hide')
                toastr.error(data.msg);
            })
        });

    </script>

</div>